package com.hunttown.common.sharding.client.datasource;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.sql.DataSource;

public class ShardingDataSources {
    private static ShardingDataSources shardingDataSources = new ShardingDataSources();
    private Map<String, DataSource> dataSourceMap = new ConcurrentHashMap();

    private ShardingDataSources() {
    }

    public static ShardingDataSources getInstance() {
        return shardingDataSources;
    }

    public synchronized void addDataSource(String dataSourceName, DataSource dataSource) {
        if (!this.dataSourceMap.containsKey(dataSourceName)) {
            this.dataSourceMap.put(dataSourceName, dataSource);
        }

    }

    public DataSource getDataSource(String dataSourceName) {
        return (DataSource) this.dataSourceMap.get(dataSourceName);
    }
}